package com.company.project.service.impl;

import com.company.project.dao.RoleMapper;
import com.company.project.model.Role;
import com.company.project.model.RoleAuthority;
import com.company.project.model.Thesis;
import com.company.project.model.User;
import com.company.project.service.RoleService;
import com.company.project.core.AbstractService;
import com.company.project.util.PageUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;


/**
 * Created by CodeGenerator on 2018/10/08.
 */
@Service
@Transactional
public class RoleServiceImpl extends AbstractService<Role> implements RoleService {
    @Resource
    private RoleMapper roleMapper;

    /**
     * 删除用户
     * @param rid
     * @return
     */
    @Override
    public Boolean deleteRole(Integer rid) {
        return roleMapper.deleteRole(rid);
    }

    @Override
    public PageUtil<Role> selectRoleWithAuthority(Integer pageIndex) {
        PageUtil<Role> pageUtil = new PageUtil();
        pageUtil.setPageSize(15);
        pageUtil.setCpage(pageIndex);
        pageUtil.setTotalRow(this.selectRoleUnm());
        pageUtil.setLists(roleMapper.selectRoleWithAuthority(pageUtil));
        return pageUtil;
    }

    @Override
    public Integer selectRoleUnm() {
        return roleMapper.selectRoleUnm();
    }

    /**
     * 更新role
     * @param roleAuthority
     * @return
     */
    @Override
    public Boolean upRole(RoleAuthority roleAuthority) {
        return roleMapper.upRole(roleAuthority);
    }

    /**
     * 查询
     * @return
     */
    @Override
    public List<Role> selectRole() {
        return roleMapper.selectRole();
    }


    /**
     * 添加角色
     * @param roleAuthority
     * @return
     */
    @Override
    public Boolean addRole(RoleAuthority roleAuthority) {
        return roleMapper.addRole(roleAuthority);
    }

}
